module grid_mod; 
use vec_factory;
implicit none;
logical, save :: GRID_MOD_TRACE_ENTRY = .TRUE.;

contains 

function new_step_grid(min_val, max_val, vsize) result(vec_p);    implicit none;  
  real(R14), dimension(:), pointer :: vec_p;      
  integer, intent(in) :: vsize;
  real(R14), intent(in) :: min_val, max_val;
  call dbg_info("-->new_step_grid()", GRID_MOD_TRACE_ENTRY);
  vec_p => make_vec_step(min_val, max_val, vsize);
  return;
end function

! only checks two intervals at the front and two at the back
SUBROUTINE assert_step_grid_4(px);    implicit none;  
  real(R14), dimension(:), pointer :: px;      
  real(R14) st, st2;
  integer xn, mini, maxi;
  xn = SIZE(px, 1);  mini = LBOUND(px, 1); maxi = UBOUND(px, 1);
  call assert_true("xn >= 3", xn >= 3); ! pointless if < 3
  call assert_true("px(mini+1)>px(mini)", px(mini+1)>px(mini));
  call assert_true("px(maxi)>px(maxi-1)", px(maxi)>px(maxi-1));
  
  st = px(mini + 1) - px(mini);
  st2 = px(mini + 2) - px(mini + 1);
  call assert_max_diff("mini", st, st2, ERR14);
  st = px(maxi) - px(maxi - 1);
  call assert_max_diff("mini,maxi", st, st2, ERR14);
  st2 = px(maxi - 1) - px(maxi - 2);
  call assert_max_diff("maxi", st, st2, ERR14);
  return;
end SUBROUTINE

end module 